<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>个人资料</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/renting/css/public.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/renting/css/layui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/header.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/bottom.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/personal_public.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/renting/css/personal.css"/>
    <link rel="icon" href="${pageContext.request.contextPath}/layui/images/favicon.ico">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layuimini.css?v=2.0.4.2" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/themes/default.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<style type="text/css">
    .layui-input-inline{
        width: 60%;
    }
    .item b{
        width: 120px;
    }
</style>
</head>
<body>
<div class="header">
    <div class="nav">
        <a href="${pageContext.request.contextPath}/renting/index.jsp" class="nav_title">好客租房</a>
        <select class="select">
            <option value="重庆">重庆</option>
            <option value="贵阳">贵阳</option>
            <option value="重庆">重庆</option>
            <option value="贵阳">贵阳</option>
        </select>
        <ul class="nav_ul">
            <li><a href="${pageContext.request.contextPath}/renting/index.jsp">首页</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/Findroom.jsp">轻松找房</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/entry.jsp">房东入驻</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/chat_news.jsp">消息</a></li>
            <li><a href="${pageContext.request.contextPath}/renting/pages/onther/login.jsp" style="color: #2981c8;">登录</a></li>
        </ul>
        <img src="${pageContext.request.contextPath}/renting/img/icon/lianxi-1.png" class="nav_img" style="margin-top: -20px;">
        <p class="nav_phone">
            <span>13301131116</span>
            <span>13301131116</span>
        </p>
    </div>
</div>
<div class="body">
    <div class="content">
        <div class="right_body" style="margin-right:8% ; ">
            <div class="right_content">
                <div class="item" style="text-align: center;line-height: 60px;color: #0c7cb5">
                    <h1>基本信息修改界面</h1>
                </div>
                <div class="item">
                    <b>姓名</b>
                    <div class="layui-input-inline">
                        <input type="text" id="userName" value="${drom.name==null?'':drom.name}" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                    </div>
                    <i></i>
                <%--                    <span>${dorm.phone==null?'您未登陆':drom.name==null?'您未设置名称':drom.name}</span>--%>
                </div>
                <div class="item">
                    <b>性别</b>
                    <select ${drom.sex==null?'':'disabled'} id="userSex" style="width: 60%;height: 36px">
                        <option value="${drom.sex==null?'-1':drom.sex==1?'1':'0'}">${drom.sex==null?'请设置性别':drom.sex==1?'男':'女'}</option>
                        <option value="1">男</option>
                        <option value="0">女</option>
                    </select>
                    <i style="color: orange">仅可修改一次！</i>
<%--                    <span>${dorm.phone==null?'您未登陆':drom.sex==null?'未设置性别':drom.sex}</span>--%>
                </div>
                <div class="item">
                    <b>手机号</b>
                    <div class="layui-input-inline">
                        <input id="userPhone" value="${drom.phone==null?'':drom.phone}" type="text" required lay-verify="required" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
                    </div>
                    <i></i>
<%--                    <span>${dorm.phone==null?'您未登陆':drom.phone==null?'您未设置电话号码':drom.phone}</span>--%>
                </div>
                <div class="item">
                    <b>身份证号码</b>
                    <div class="layui-input-inline">
                        <input type="text" id="userIdCode" value="${drom.idCard==null?'':drom.idCard}" required lay-verify="required" placeholder="请输入身份证号码" autocomplete="off" class="layui-input">
                    </div>
                    <i></i>
<%--                    <span>${dorm.phone==null?'您未登陆':drom.idCard==null?'您未设置身份证号码':drom.idCard}</span>--%>
                </div>
                <div class="item">
                    <b>职业信息</b>
                    <select id="userOpration" style="width: 60%;height: 36px;">
                        <option value="${drom.jobInfo==null?'-1':drom.jobInfo}">${drom.jobInfo==null?'请设置您的职业信息':drom.jobInfo}</option>
                        <option value="学生">学生</option>
                        <option value="教育人员">教育人员</option>
                        <option value="工人">工人</option>
                        <option value="白领">白领</option>
                        <option value="网络工程师">网络工程师</option>
                        <option value="程序员">程序员</option>
                        <option value="自由职业">自由职业</option>
                        <option value="其他">其他</option>
                    </select>
<%--                    <span>${dorm.phone==null?'您未登陆':drom.jobInfo==null?(drom.isHouse==1?'房东':'您未设置职业'):drom.jobInfo}</span>--%>
                </div>
                <div style="margin-top: 20px">
                    <a class="layui-btn" href="personal.jsp">返回</a>
                    <a id="subChageMsg" style="float: right" class="layui-btn layui-btn-normal">保存修改信息</a>
                </div>
            </div>
        </div>
        <div style="clear: both;"></div>
    </div>
</div>
<div class="bottom">
    <p>沪公网安备 31011402005354号</p>
</div>
</body>
</html>
<script src="${pageContext.request.contextPath}/renting/js/jQuery-3.4.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/layui/lib/layui-v2.6.3/layui.js"></script>
<script src="${pageContext.request.contextPath}/renting/js/landlord_public.js"></script>
<script src="${pageContext.request.contextPath}/renting/js/personal.js"></script>
<script src="${pageContext.request.contextPath}/renting/js/header.js"></script>
<script src="../../js/tool.js"></script>
<script type="text/javascript">
    var login=sessionStorage.getItem("login");
    var url="";
    if(login==1){
        url="${pageContext.request.contextPath}/renting/pages/tenant/inspection.jsp";
    }
    if(login==2){
        url="${pageContext.request.contextPath}/renting/pages/landlord/release.jsp";
    }
    judge_login(url,"${pageContext.request.contextPath}/renting/pages/onther/login.jsp");


    //layui全局
    layui.use(['layer'],function (){

        //基本信息验证
        //姓名验证
        $("#userName").blur(function (){
            var values = $(this).val().trim();
            var iobj = $(this).parent().siblings("i");
            if(values.length<2){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("您的名字太短了，请修改");
            }else{
                iobj.text("");
                iobj.css("color","#1fa363");
                iobj.css("font-size","30px");
                iobj.addClass("layui-icon layui-icon-ok");
                cgname=values;
            }
        })

        //手机号码验证
        $("#userPhone").blur(function (){
            var values = $(this).val().trim();
            var iobj = $(this).parent().siblings("i");
            if(values.length!=11){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("电话号码位数不对");
            }else if(values.length<1){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("电话号码不能为空");
            }else if(!checkPhoneNum(values)){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("您的对电话号码格式不正确");
            }else{
                iobj.text("");
                iobj.css("color","#1fa363");
                iobj.css("font-size","30px");
                iobj.addClass("layui-icon layui-icon-ok");
                cgphone=values;
            }
        })

        //身份证号码验证
        $("#userIdCode").blur(function (){
            var values = $(this).val().trim();
            var iobj = $(this).parent().siblings("i");
            if(values.length!=18){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("身份证号码位数不对");
            }else if(values.length<1){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("身份证号码不能为空");
            } else if(!checkID(values)){
                iobj.removeClass("layui-icon layui-icon-ok")
                iobj.css("color","red");
                iobj.css("font-size","16px");
                iobj.text("身份证号码格式不对");
            }else {
                iobj.text("");
                iobj.css("color","#1fa363");
                iobj.css("font-size","30px");
                iobj.addClass("layui-icon layui-icon-ok");
                cgidcode=values;
            }
        })




        //提交修改验证
        $("#subChageMsg").click(function (){
            var cgname=$("#userName").val(),cgphone=$("#userPhone").val(),cgidcode=$("#userIdCode").val();
            if(cgname.length<1){
                layer.msg("请检查您的名称，可能太短或者没有输入",{icon:2});
            }else{
                if(cgphone.length!=11){
                    layer.msg("您的电话号码没有输入正确，位数不对",{icon:2});
                }else if(!checkPhoneNum(cgphone)){
                    layer.msg("您的电话号码格式不正确",{icon:2});
                }else{
                    var usersex = $("#userSex").val();
                    if(usersex==-1){
                        layer.msg("请选择您的性别",{icon:2})
                    }else{
                        if(cgidcode.length<18){
                            layer.msg("您的身份证号码位数不对，请检查",{icon:2})
                        }else if(!checkID(cgidcode)){
                            layer.msg("您的对身份证号码格式不对哦",{icon:2})
                        }else{
                            var opration = $("#userOpration").val();
                            $.ajax({
                                url:'${pageContext.request.contextPath}/userInfo/updateUser',
                                type:'post',
                                async:false,
                                data:{"name":cgname,"sex":$("#userSex").val(),"phone":cgphone,"idcode":cgidcode,"opration":$("#userOpration").val()},
                                dataType:'json',
                                success:function (redata){
                                    if(redata.statecode==0){
                                        layer.msg("您的信息修改成功，请刷新界面查看新数据");
                                    }else{
                                        layer.msg("网络异常，修改失败")
                                    }

                                    console.log(redata);
                                },
                                error:function (e){
                                    console.log(e)
                                }
                            })
                        }
                    }
                }
            }
            return false;
        })






        //点击下拉时清空第一行
        $("select").click(function (){
            if($(this).children("option").eq(0).text()=="请设置您的职业信息"||$(this).children("option").eq(0).text()=="请设置性别"){
                $(this).children("option").eq(0).text("");
            }
            return false;
        })

        //点击界面添加第一行
        $(document).click(function (){
            $("#userSex option:eq(0)").text('${drom.sex==null?'请设置性别':drom.sex==1?'男':'女'}');
            $("#userOpration option:eq(0)").text('${drom.jobInfo==null?'请设置您的职业信息':drom.jobInfo}')
        });

    })












</script>
